//
//  WYReplayCell.m
//  Boss
//
//  Created by admin on 2018/8/6.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYReplayCell.h"
#import "YYText.h"
@interface WYReplayCell()
@property (nonatomic,strong) YYLabel *introLabel;

@end


@implementation WYReplayCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
//        _replayLabel = [[UILabel alloc]init];
//        _replayLabel.numberOfLines = 0;
//        _replayLabel.font = [UIFont systemFontOfSize:12];
//      //  [self addSubview:_replayLabel];
//        [_replayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.right.mas_equalTo(0);
//            make.top.mas_equalTo(5);
//            make.bottom.mas_equalTo(0);
//        }];
//        _replayLabel.textColor = [UIColor hexStringToColor:@"#666666" alpha:1.0];
        
        
        
        YYLabel *introLabel = [YYLabel new];
        self.introLabel = introLabel;
        [self.contentView addSubview:introLabel];
      
        introLabel.numberOfLines = 0;
        introLabel.preferredMaxLayoutWidth =(kScreenWidth - 2 * 16);
        introLabel.left = 16;
        introLabel.width = (kScreenWidth - 2 * 16);
        introLabel.textVerticalAlignment = YYTextVerticalAlignmentTop;
        introLabel.displaysAsynchronously = YES;
        introLabel.ignoreCommonProperties = YES;
        introLabel.fadeOnHighlight = NO;
        introLabel.font = [UIFont systemFontOfSize:12];
        WEAKSELF
        introLabel.highlightTapAction = ^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect) {
//            if ([weakSelf.delegate respondsToSelector:@selector(cell:didClickInLabel:textRange:WithOutLink:)]) {
//                [weakSelf.delegate cell:weakSelf didClickInLabel:(YYLabel *)containerView textRange:range WithOutLink:self.outLink];
//            }
            NSLog(@"测试点击");
            
            
        };
        
        //    introLabel.highlightTapAction(<#UIView * _Nonnull containerView#>, <#NSAttributedString * _Nonnull text#>, <#NSRange range#>, <#CGRect rect#>)
        [introLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(0);
            make.top.mas_equalTo(5);
            make.bottom.mas_equalTo(0);
        }];
        
        
        
    }
    return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)setText:(NSString *)text
{
    _text = text;
    

    
    
}
-(void)setModel:(WYReplyList *)model
{
    _model = model;
    
    NSString *str = [NSString stringWithFormat:@"%@ 回复 %@: %@ ",model.fromUserName,model.toUserName,model.content];
    
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:str];
    //        [attributedString addAttribute:NSForegroundColorAttributeName value:[UIFont systemFontOfSize:18] range:NSMakeRange(0, attributedString.length)];


    [attributedString yy_setFont:[UIFont systemFontOfSize:12] range:NSMakeRange(0, attributedString.length)];

    NSString *string = [NSString stringWithFormat:@"%@ 回复 %@:",model.fromUserName,model.toUserName];
    NSRange searchRange = NSMakeRange(0, attributedString.string.length);
    NSRange range = [attributedString.string rangeOfString:string options:kNilOptions range:searchRange];
    if (range.location == NSNotFound) return;
    if ([attributedString yy_attribute:YYTextHighlightAttributeName atIndex:range.location] == nil) {
        [attributedString yy_setColor:[UIColor hexStringToColor:@"#527ead" alpha:1.0] range:range];

        // 高亮状态
        YYTextHighlight *highlight = [YYTextHighlight new];
        //[highlight setBackgroundBorder:highlightBorder];
        // 数据信息，用于稍后用户点击
        //  highlight.userInfo = @{kWBLinkTopicName : topic};
        [attributedString yy_setTextHighlight:highlight range:range];
    }

    //


    //        [attributedString addAttribute:NSForegroundColorAttributeName value:[UIFont systemFontOfSize:18] alpha:1.0] range:NSMakeRange(0, attributedString.length)];

    //    searchRange.location = searchRange.location + (searchRange.length ? searchRange.length : 1);
    //    if (searchRange.location + 1>= attributedString.length) return;
    //    searchRange.length = attributedString.length - searchRange.location;
    self.introLabel.attributedText = attributedString;
    
}


@end
